package day3;

/**
 * ClassName：Student
 *
 * @Author：小鱼
 * @Create：2025-08-13 14:22
 */
public class Student implements Comparable<Student>{
    //属性
    private String name;
    private int age;
    private double score;

    //构造函数
    public Student() {
    }

    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    //get，set函数
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }

    //重写toString方法
    @Override
    public String toString() {
        return "\nStudent{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        int num;
        //叫tom的学⽣不管考多少分都位于班级的第⼀位
        if("tom".equals(this.name)){
            return -1;
        }
        if("tom".equals(o.name)){
            return 1;
        }
        //name进行降序排序
        num = -(this.name.compareTo(o.name));
        if(num==0){
            //age升序排序
            num = age-o.age;
        }
        if(num==0){
            //score降序排序
            num = -Double.compare(this.score, o.score);
        }
        return num;
    }
}
